const express=require('express');
const db=require('../utils/db.js');

const router=express.Router();

router.post('/selsettlelocation',(req,res)=>{
	const sql=`SELECT * FROM location WHERE id='${req.body.selectlid}';`
	db.query(sql,(err,data)=>{
		if(err){
			res.send({msg:err})
		}else{
			res.send(data)
		}
	})
})
router.post('/selsettleCouponNum',(req,res)=>{
	const sql=`SELECT phone,takeawayCoupon,canteenCoupon FROM userinfo WHERE id='${req.body.userid}';`
	db.query(sql,(err,data)=>{
		if(err){
			res.send({msg:err})
		}else{
			res.send(data)
		}
	})
})
router.post('/selsettleCoupon',(req,res)=>{
	const sql=`SELECT * FROM coupon WHERE user_id='${req.body.userid}';`
	db.query(sql,(err,data)=>{
		if(err){
			res.send({msg:err})
		}else{
			res.send(data)
		}
	})
})
router.post('/editCoupon',(req,res)=>{
	const sql=`UPDATE userinfo set takeawayCoupon='${req.body.takeawayCoupon}',canteenCoupon='${req.body.canteenCoupon}' where id='${req.body.userid}';`
	db.query(sql,(err,data)=>{
		if(err){
			res.send({msg:err})
		}else{
			res.send({msg:'减少'})
		}
	})
})

router.post('/delectCoupon',(req,res)=>{
	const sql=`DELETE FROM coupon where id=${req.body.id};`;
	db.query(sql,(err,data)=>{
		if(err){
			res.send({msg:err})
		}else{
			res.send({msg:'成功'})
		}
	})
})
module.exports=router;